import 'dart:developer';

import 'package:dio/dio.dart';
import 'package:flutter_base/page/common/loading_toast.dart';

///
/// @DIR_PATH：lib/http
/// @TIME：2024/6/6 18:47
/// @AUTHOR：starr
///
class PrintLogInterceptor extends InterceptorsWrapper{


  //发起请求的信息
  @override
  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
    log("\nrequest----------->");
    options.headers.forEach((key, value) {
      log("请求头信息：key=$key value=${value.toString()}");
    });
    log("path:${options.uri}");
    log("method:${options.method}");
    log("data:${options.data}");
    log("queryParams:${options.queryParameters.toString()}");
    log("<----------request\n");
    super.onRequest(options, handler);
  }

  //请求得到的结果
@override
  void onResponse(Response response, ResponseInterceptorHandler handler) {
  log("\nresponse----------->");
  log("path:${response.realUri}");
  log("header:${response.headers.toString()}");
  log("statusMessage:${response.statusMessage}");
  log("statusCode:${response.statusCode}");
  log("extra:${response.extra.toString()}");
  log("data:${response.data.toString()}");
  log("<----------response\n");
    super.onResponse(response, handler);
  }


  //请求异常
@override
  void onError(DioError err, ErrorInterceptorHandler handler) {
  log("\nonError----------->");
  log("err:${err.toString()}");
  log("<----------onError\n");
    super.onError(err, handler);
  }
}